﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using BaseHelper.Http;
using BaseHelper.Base;

namespace DeviceSDK.NetTraffic.HighWay
{
    public class HebeiApi
    {
        public static Hashtable Get_StationInfo(string StationName,string Direction ="",string K="")
        {
            StationName = StationName.Replace("，", ",");
            string[] stations = StationName.Contains(",") ? StationName.Split(',') : new string[] { StationName };
            HttpHelperLite http = new HttpHelperLite();

            Hashtable htRet = new Hashtable();
            ArrayList alResult=new ArrayList();

            string url, html;
            //收费站信息 xxlx001
            url = "http://www.hebecc.com/traffic/getTrafficByType?informationType=xxlx001";
            html = http.Get(url);
            if (html.Contains("code\":\"20000"))
            {
                Hashtable htResult = (Hashtable)JsonHelper.Decode(html);
                ArrayList alList = (ArrayList)htResult["result"];
                if (alList.Count > 0)
                {
                    alResult.AddRange(alList);
                }
            }


            url = "http://www.hebecc.com/traffic/getTrafficByType?informationType=xxlx006";
            html = http.Get(url);
            if (html.Contains("code\":\"20000"))
            {
                Hashtable htResult = (Hashtable)JsonHelper.Decode(html);
                ArrayList alList = (ArrayList)htResult["result"];
                if (alList.Count > 0)
                {
                    alResult.AddRange(alList);
                }
            }

            if(alResult.Count>0)
            {
                foreach (Hashtable ht in alResult)
                {
                    foreach (string station in stations)
                    {
                        
                        if (ht["stationName"].ToString().StartsWith(station))
                        {
                            if (Direction == "" || (Direction != "" && (ht["direction"].ToString() == Direction || ht["direction"].ToString().Contains("双向"))))
                            {
                                if (!htRet.ContainsKey(station))
                                {
                                    htRet.Add(station, new List<Hashtable>());
                                }
                                List<Hashtable> lt = (List<Hashtable>)htRet[station];
                                lt.Add(ht);
                                //htRet[station] = lt;
                            }
                        }

                    }
                }
            }
     
            return htRet;
        }

        public static Hashtable GetRoadInfo(string RoadName, string Direction = "",string K="")
        {
            string[] roads = RoadName.Contains(",") ? RoadName.Split(',') : new string[] { RoadName };
            HttpHelperLite http = new HttpHelperLite();

            Hashtable htRet = null;
            ArrayList alResult = new ArrayList();

            string url, html;
            //收费站信息 xxlx001
            url = "http://www.hebecc.com/traffic/getTrafficByType?informationType=xxlx001";
            html = http.Get(url);
            if (html.Contains("code\":\"20000"))
            {
                Hashtable htResult = (Hashtable)JsonHelper.Decode(html);
                ArrayList alList = (ArrayList)htResult["result"];
                if (alList.Count > 0)
                {
                    alResult.AddRange(alList);
                }
            }


            url = "http://www.hebecc.com/traffic/getTrafficByType?informationType=xxlx006";
            html = http.Get(url);
            if (html.Contains("code\":\"20000"))
            {
                Hashtable htResult = (Hashtable)JsonHelper.Decode(html);
                ArrayList alList = (ArrayList)htResult["result"];
                if (alList.Count > 0)
                {
                    alResult.AddRange(alList);
                }
            }

            if (alResult.Count > 0)
            {
                htRet = new Hashtable();
                foreach (Hashtable ht in alResult)
                {
                    foreach (string station in roads)
                    {
                        if (ht["stationName"].ToString().StartsWith(station))
                        {
                            if (Direction == "" || (Direction != "" && (ht["direction"].ToString() == Direction || ht["direction"].ToString().Contains("双向"))))
                                if (!htRet.ContainsKey(station))
                                {
                                    htRet.Add(station, new List<Hashtable>());
                                }
                            List<Hashtable> lt = (List<Hashtable>)htRet[station];
                            lt.Add(ht);
                            //htRet[station] = lt;

                        }

                    }
                }
            }

            return htRet;
        }
    }
}
